home *** CD-ROM | disk | FTP | other *** search
-
-
-
- SH User Commands SH
-
-
-
- NNAAMMEE
- sh, for, case, if, while, ::, .., break, continue, cd, eval,
- exec, exit, export, login, read, readonly, set, shift,
- times, trap, umask, wait - command language
-
- SSYYNNOOPPSSIISS
- sshh [ --cceeiikknnrrssttuuvvxx ] [ arg ] ...
-
- DDEESSCCRRIIPPTTIIOONN
- _S_h is a command programming language that executes commands
- read from a terminal or a file. See iinnvvooccaattiioonn for the
- meaning of arguments to the shell.
-
- CCoommmmaannddss..
- A _s_i_m_p_l_e-_c_o_m_m_a_n_d is a sequence of non blank _w_o_r_d_s separated
- by blanks (a blank is a ttaabb or a ssppaaccee). The first word
- specifies the name of the command to be executed. Except as
- specified below the remaining words are passed as arguments
- to the invoked command. The command name is passed as argu-
- ment 0 (see _e_x_e_c_v_e(2)). The _v_a_l_u_e of a simple-command is
- its exit status if it terminates normally or 200+_s_t_a_t_u_s if
- it terminates abnormally (see _s_i_g_v_e_c(2) for a list of status
- values).
-
- A _p_i_p_e_l_i_n_e is a sequence of one or more _c_o_m_m_a_n_d_s separated
- by ||.. The standard output of each command but the last is
- connected by a _p_i_p_e(2) to the standard input of the next
- command. Each command is run as a separate process; the
- shell waits for the last command to terminate.
-
- A _l_i_s_t is a sequence of one or more _p_i_p_e_l_i_n_e_s separated by
- ;;, &&, &&&& or |||| and optionally terminated by ;; or &&. ;; and &&
- have equal precedence which is lower than that of &&&& and ||||,
- &&&& and |||| also have equal precedence. A semicolon causes
- sequential execution; an ampersand causes the preceding
- _p_i_p_e_l_i_n_e to be executed without waiting for it to finish.
- The symbol &&&& (||||) causes the _l_i_s_t following to be executed
- only if the preceding _p_i_p_e_l_i_n_e returns a zero (non zero)
- value. Newlines may appear in a _l_i_s_t, instead of semi-
- colons, to delimit commands.
-
- A _c_o_m_m_a_n_d is either a simple-command or one of the follow-
- ing. The value returned by a command is that of the last
- simple-command executed in the command.
-
- ffoorr _n_a_m_e [iinn _w_o_r_d ...] ddoo _l_i_s_t ddoonnee
- Each time a ffoorr command is executed _n_a_m_e is set to the
- next word in the ffoorr word list. If iinn _w_o_r_d ... is
- omitted, iinn ""$$@@"" is assumed. Execution ends when there
- are no more words in the list.
-
- ccaassee _w_o_r_d iinn [_p_a_t_t_e_r_n [ || _p_a_t_t_e_r_n ] ... )) _l_i_s_t ;;;;] ... eessaacc
-
-
-
- Sprite v1.0 May 5, 1986 1
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- A ccaassee command executes the _l_i_s_t associated with the
- first pattern that matches _w_o_r_d. The form of the pat-
- terns is the same as that used for file name genera-
- tion.
-
- iiff _l_i_s_t tthheenn _l_i_s_t [eelliiff _l_i_s_t tthheenn _l_i_s_t] ... [eellssee _l_i_s_t] ffii
- The _l_i_s_t following iiff is executed and if it returns
- zero the _l_i_s_t following tthheenn is executed. Otherwise,
- the _l_i_s_t following eelliiff is executed and if its value is
- zero the _l_i_s_t following tthheenn is executed. Failing that
- the eellssee _l_i_s_t is executed.
-
- wwhhiillee _l_i_s_t [ddoo _l_i_s_t] ddoonnee
- A wwhhiillee command repeatedly executes the wwhhiillee _l_i_s_t and
- if its value is zero executes the ddoo _l_i_s_t; otherwise
- the loop terminates. The value returned by a wwhhiillee
- command is that of the last executed command in the ddoo
- _l_i_s_t. uunnttiill may be used in place of wwhhiillee to negate the
- loop termination test.
-
- (( _l_i_s_t ))
- Execute _l_i_s_t in a subshell.
-
- {{ _l_i_s_t }}
- _l_i_s_t is simply executed.
-
- The following words are only recognized as the first word of
- a command and when not quoted.
-
- iiff tthheenn eellssee eelliiff ffii ccaassee iinn eessaacc ffoorr wwhhiillee uunnttiill ddoo
- ddoonnee {{ }}
-
- CCoommmmaanndd ssuubbssttiittuuttiioonn..
- The standard output from a command enclosed in a pair of
- back quotes (````) may be used as part or all of a word;
- trailing newlines are removed.
-
- PPaarraammeetteerr ssuubbssttiittuuttiioonn..
- The character $$ is used to introduce substitutable parame-
- ters. Positional parameters may be assigned values by sseett.
- Variables may be set by writing
-
- _n_a_m_e==_v_a_l_u_e [ _n_a_m_e==_v_a_l_u_e ] ...
-
- ${{_p_a_r_a_m_e_t_e_r}}
- A _p_a_r_a_m_e_t_e_r is a sequence of letters, digits or under-
- scores (a _n_a_m_e), a digit, or any of the characters ** @@
- ## ?? -- $$ !!.. The value, if any, of the parameter is sub-
- stituted. The braces are required only when _p_a_r_a_m_e_t_e_r
- is followed by a letter, digit, or underscore that is
- not to be interpreted as part of its name. If _p_a_r_a_m_e_-
- _t_e_r is a digit, it is a positional parameter. If
-
-
-
- Sprite v1.0 May 5, 1986 2
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- _p_a_r_a_m_e_t_e_r is ** or @@ then all the positional parameters,
- starting with $$11, are substituted separated by spaces.
- $$00 is set from argument zero when the shell is invoked.
-
- ${{_p_a_r_a_m_e_t_e_r-_w_o_r_d}}
- If _p_a_r_a_m_e_t_e_r is set, substitute its value; otherwise
- substitute _w_o_r_d.
-
- ${{_p_a_r_a_m_e_t_e_r=_w_o_r_d}}
- If _p_a_r_a_m_e_t_e_r is not set, set it to _w_o_r_d; the value of
- the parameter is then substituted. Positional parame-
- ters may not be assigned to in this way.
-
- ${{_p_a_r_a_m_e_t_e_r?_w_o_r_d}}
- If _p_a_r_a_m_e_t_e_r is set, substitute its value; otherwise,
- print _w_o_r_d and exit from the shell. If _w_o_r_d is omit-
- ted, a standard message is printed.
-
- ${{_p_a_r_a_m_e_t_e_r+_w_o_r_d}}
- If _p_a_r_a_m_e_t_e_r is set, substitute _w_o_r_d; otherwise substi-
- tute nothing.
-
- In the above _w_o_r_d is not evaluated unless it is to be used
- as the substituted string. (So that, for example, echo
- ${d-'pwd'} will only execute _p_w_d if _d is unset.)
-
- The following _p_a_r_a_m_e_t_e_r_s are automatically set by the shell.
-
- ## The number of positional parameters in decimal.
- -- Options supplied to the shell on invocation or by
- sseett.
- ?? The value returned by the last executed command in
- decimal.
- $$ The process number of this shell.
- !! The process number of the last background command
- invoked.
-
- The following _p_a_r_a_m_e_t_e_r_s are used but not set by the shell.
-
- HHOOMMEE The default argument (home directory) for the ccdd
- command.
- PPAATTHH The search path for commands (see eexxeeccuuttiioonn).
- MMAAIILL If this variable is set to the name of a mail
- file, the shell informs the user of the arrival of
- mail in the specified file.
- PPSS11 Primary prompt string, by default '$ '.
- PPSS22 Secondary prompt string, by default '> '.
- IIFFSS Internal field separators, normally ssppaaccee, ttaabb,
- and nneewwlliinnee. IIFFSS is ignored if _s_h is running as
- root or if the effective user id differs from the
- real user id.
-
-
-
-
- Sprite v1.0 May 5, 1986 3
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- BBllaannkk iinntteerrpprreettaattiioonn..
- After parameter and command substitution, any results of
- substitution are scanned for internal field separator char-
- acters (those found in $$IIFFSS) and split into distinct argu-
- ments where such characters are found. Explicit null argu-
- ments ("" or '') are retained. Implicit null arguments
- (those resulting from _p_a_r_a_m_e_t_e_r_s that have no values) are
- removed.
-
- FFiillee nnaammee ggeenneerraattiioonn..
- Following substitution, each command word is scanned for the
- characters **, ?? and [[.. If one of these characters appears,
- the word is regarded as a pattern. The word is replaced
- with alphabetically sorted file names that match the pat-
- tern. If no file name is found that matches the pattern,
- the word is left unchanged. The character .. at the start of
- a file name or immediately following a //, and the character
- //, must be matched explicitly.
-
- ** Matches any string, including the null string.
- ?? Matches any single character.
- [[......]]
- Matches any one of the characters enclosed. A pair of
- characters separated by -- matches any character lexi-
- cally between the pair.
-
- QQuuoottiinngg..
- The following characters have a special meaning to the shell
- and cause termination of a word unless quoted.
-
- ;; && (( )) || << >> nneewwlliinnee ssppaaccee ttaabb
-
- A character may be _q_u_o_t_e_d by preceding it with a \\.. \\nneeww--
- lliinnee is ignored. All characters enclosed between a pair of
- quote marks (''''), except a single quote, are quoted. Inside
- double quotes ("""") parameter and command substitution occurs
- and \\ quotes the characters \\ '' "" and $$.
-
- ""$$**"" is equivalent to ""$$11 $$22 ......"" whereas
- ""$$@@"" is equivalent to ""$$11"" ""$$22"" ...... ..
-
- PPrroommppttiinngg..
- When used interactively, the shell prompts with the value of
- PS1 before reading a command. If at any time a newline is
- typed and further input is needed to complete a command, the
- secondary prompt ($$PPSS22) is issued.
-
- IInnppuutt oouuttppuutt..
- Before a command is executed its input and output may be
- redirected using a special notation interpreted by the
- shell. The following may appear anywhere in a simple-
- command or may precede or follow a _c_o_m_m_a_n_d and are not
-
-
-
- Sprite v1.0 May 5, 1986 4
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- passed on to the invoked command. Substitution occurs
- before _w_o_r_d or _d_i_g_i_t is used.
-
- <_w_o_r_d
- Use file _w_o_r_d as standard input (file descriptor 0).
-
- >_w_o_r_d
- Use file _w_o_r_d as standard output (file descriptor 1).
- If the file does not exist, it is created; otherwise it
- is truncated to zero length.
-
- >>_w_o_r_d
- Use file _w_o_r_d as standard output. If the file exists,
- output is appended (by seeking to the end); otherwise
- the file is created.
-
- <<_w_o_r_d
- The shell input is read up to a line the same as _w_o_r_d,
- or end of file. The resulting document becomes the
- standard input. If any character of _w_o_r_d is quoted, no
- interpretation is placed upon the characters of the
- document; otherwise, parameter and command substitution
- occurs, \\nneewwlliinnee is ignored, and \\ is used to quote the
- characters \\ $$ '' and the first character of _w_o_r_d.
-
- <&_d_i_g_i_t
- The standard input is duplicated from file descriptor
- _d_i_g_i_t; see _d_u_p(2). Similarly for the standard output
- using >.
-
- <&- The standard input is closed. Similarly for the stan-
- dard output using >.
-
- If one of the above is preceded by a digit, the file
- descriptor created is that specified by the digit (instead
- of the default 0 or 1). For example,
-
- ... 2>&1
-
- creates file descriptor 2 to be a duplicate of file descrip-
- tor 1.
-
- If a command is followed by && then the default standard
- input for the command is the empty file (/dev/null). Other-
- wise, the environment for the execution of a command con-
- tains the file descriptors of the invoking shell as modified
- by input output specifications.
-
- EEnnvviirroonnmmeenntt..
- The environment is a list of name-value pairs that is passed
- to an executed program in the same way as a normal argument
- list; see _e_x_e_c_v_e(2) and _e_n_v_i_r_o_n(7). The shell interacts
-
-
-
- Sprite v1.0 May 5, 1986 5
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- with the environment in several ways. On invocation, the
- shell scans the environment and creates a _p_a_r_a_m_e_t_e_r for each
- name found, giving it the corresponding value. Executed
- commands inherit the same environment. If the user modifies
- the values of these _p_a_r_a_m_e_t_e_r_s or creates new ones, none of
- these affects the environment unless the eexxppoorrtt command is
- used to bind the shell's _p_a_r_a_m_e_t_e_r to the environment. The
- environment seen by any executed command is thus composed of
- any unmodified name-value pairs originally inherited by the
- shell, plus any modifications or additions, all of which
- must be noted in eexxppoorrtt commands.
-
- The environment for any _s_i_m_p_l_e-_c_o_m_m_a_n_d may be augmented by
- prefixing it with one or more assignments to _p_a_r_a_m_e_t_e_r_s.
- Thus these two lines are equivalent
-
- TERM=450 cmd args
- (export TERM; TERM=450; cmd args)
-
- If the --kk flag is set, _a_l_l keyword arguments are placed in
- the environment, even if the occur after the command name.
- The following prints 'a=b c' and 'c':
- echo a=b c
- set -k
- echo a=b c
-
- SSiiggnnaallss..
- The INTERRUPT and QUIT signals for an invoked command are
- ignored if the command is followed by &&; otherwise signals
- have the values inherited by the shell from its parent.
- (But see also ttrraapp..)
-
- EExxeeccuuttiioonn..
- Each time a command is executed the above substitutions are
- carried out. Except for the 'special commands' listed below
- a new process is created and an attempt is made to execute
- the command via an _e_x_e_c_v_e(2).
-
- The shell parameter $$PPAATTHH defines the search path for the
- directory containing the command. Each alternative direc-
- tory name is separated by a colon (::). The default path is
- :://bbiinn:://uussrr//bbiinn. If the command name contains a /, the
- search path is not used. Otherwise, each directory in the
- path is searched for an executable file. If the file has
- execute permission but is not an _a._o_u_t file, it is assumed
- to be a file containing shell commands. A subshell (i.e., a
- separate process) is spawned to read it. A parenthesized
- command is also executed in a subshell.
-
- SSppeecciiaall ccoommmmaannddss..
- The following commands are executed in the shell process and
- except where specified no input output redirection is
-
-
-
- Sprite v1.0 May 5, 1986 6
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- permitted for such commands.
-
- ## For non-interactive shells, everything following the ##
- is treated as a comment, i.e. the rest of the line is
- ignored. For interactive shells, the ## has no special
- effect.
-
- :: No effect; the command does nothing.
- .. _f_i_l_e
- Read and execute commands from _f_i_l_e and return. The
- search path $$PPAATTHH is used to find the directory con-
- taining _f_i_l_e.
- bbrreeaakk [_n]
- Exit from the enclosing ffoorr or wwhhiillee loop, if any. If
- _n is specified, break _n levels.
- ccoonnttiinnuuee [_n]
- Resume the next iteration of the enclosing ffoorr or wwhhiillee
- loop. If _n is specified, resume at the _n-th enclosing
- loop.
- ccdd [_a_r_g]
- Change the current directory to _a_r_g. The shell parame-
- ter $$HHOOMMEE is the default _a_r_g.
- eevvaall [_a_r_g ...]
- The arguments are read as input to the shell and the
- resulting command(s) executed.
- eexxeecc [_a_r_g ...]
- The command specified by the arguments is executed in
- place of this shell without creating a new process.
- Input output arguments may appear and if no other argu-
- ments are given cause the shell input output to be
- modified.
- eexxiitt [_n]
- Causes a non interactive shell to exit with the exit
- status specified by _n. If _n is omitted, the exit status
- is that of the last command executed. (An end of file
- will also exit from the shell.)
- eexxppoorrtt [_n_a_m_e ...]
- The given names are marked for automatic export to the
- _e_n_v_i_r_o_n_m_e_n_t of subsequently-executed commands. If no
- arguments are given, a list of exportable names is
- printed.
- llooggiinn [_a_r_g ...]
- Equivalent to 'exec login arg ...'.
- rreeaadd _n_a_m_e ...
- One line is read from the standard input; successive
- words of the input are assigned to the variables _n_a_m_e
- in order, with leftover words to the last variable.
- The return code is 0 unless the end-of-file is encoun-
- tered.
- rreeaaddoonnllyy [_n_a_m_e ...]
- The given names are marked readonly and the values of
- the these names may not be changed by subsequent
-
-
-
- Sprite v1.0 May 5, 1986 7
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- assignment. If no arguments are given, a list of all
- readonly names is printed.
- sseett [--eekknnppttuuvvxx [_a_r_g ...]]
- --ee If non interactive, exit immediately if a command
- fails.
- --kk All keyword arguments are placed in the environment
- for a command, not just those that precede the com-
- mand name.
- --nn Read commands but do not execute them.
- --tt Exit after reading and executing one command.
- --uu Treat unset variables as an error when substituting.
- --vv Print shell input lines as they are read.
- --xx Print commands and their arguments as they are exe-
- cuted.
- -- Turn off the --xx and --vv options.
-
- These flags can also be used upon invocation of the
- shell. The current set of flags may be found in $$--.
-
- Remaining arguments are positional parameters and are
- assigned, in order, to $$11, $$22, etc. If no arguments
- are given, the values of all names are printed.
-
- sshhiifftt
- The positional parameters from $$22... are renamed $$11...
-
- ttiimmeess
- Print the accumulated user and system times for
- processes run from the shell.
-
- ttrraapp [_a_r_g] [_n] ...
- _A_r_g is a command to be read and executed when the shell
- receives signal(s) _n. (Note that _a_r_g is scanned once
- when the trap is set and once when the trap is taken.)
- Trap commands are executed in order of signal number.
- If _a_r_g is absent, all trap(s) _n are reset to their ori-
- ginal values. If _a_r_g is the null string, this signal
- is ignored by the shell and by invoked commands. If _n
- is 0, the command _a_r_g is executed on exit from the
- shell, otherwise upon receipt of signal _n as numbered
- in _s_i_g_v_e_c(2). _T_r_a_p with no arguments prints a list of
- commands associated with each signal number.
-
- uummaasskk [ _n_n_n ]
- The user file creation mask is set to the octal value
- _n_n_n (see _u_m_a_s_k(2)). If _n_n_n is omitted, the current
- value of the mask is printed.
-
- wwaaiitt [_n]
- Wait for the specified process and report its termina-
- tion status. If _n is not given, all currently active
- child processes are waited for. The return code from
-
-
-
- Sprite v1.0 May 5, 1986 8
-
-
-
-
-
-
- SH User Commands SH
-
-
-
- this command is that of the process waited for.
-
- IInnvvooccaattiioonn..
- If the first character of argument zero is --, commands are
- read from $$HHOOMMEE//..pprrooffiillee, if such a file exists. Commands
- are then read as described below. The following flags are
- interpreted by the shell when it is invoked.
- --cc _s_t_r_i_n_g If the --cc flag is present, commands are read from
- _s_t_r_i_n_g.
- --ss If the --ss flag is present or if no arguments
- remain then commands are read from the standard
- input. Shell output is written to file descrip-
- tor 2.
- --ii If the --ii flag is present or if the shell input
- and output are attached to a terminal (as told by
- _g_t_t_y) then this shell is _i_n_t_e_r_a_c_t_i_v_e. In this
- case the terminate signal SIGTERM (see _s_i_g_v_e_c(2))
- is ignored (so that 'kill 0' does not kill an
- interactive shell) and the interrupt signal SIG-
- INT is caught and ignored (so that wwaaiitt is inter-
- ruptible). In all cases SIGQUIT is ignored by
- the shell.
-
- The remaining flags and arguments are described under the
- sseett command.
-
- FFIILLEESS
- $HOME/..profile
- /tmp/sh*
- /dev/null
-
- SSEEEE AALLSSOO
- csh(1), test(1), execve(2), environ(7)
-
- DDIIAAGGNNOOSSTTIICCSS
- Errors detected by the shell, such as syntax errors cause
- the shell to return a non zero exit status. If the shell is
- being used non interactively then execution of the shell
- file is abandoned. Otherwise, the shell returns the exit
- status of the last command executed (see also eexxiitt).
-
- BBUUGGSS
- If << is used to provide standard input to an asynchronous
- process invoked by &, the shell gets mixed up about naming
- the input document. A garbage file /tmp/sh* is created, and
- the shell complains about not being able to find the file by
- another name.
-
-
-
-
-
-
-
-
- Sprite v1.0 May 5, 1986 9
-
-
-
-